using System;
using Graphe.Data;

namespace Graphe
{
    public class Index
    {
        #region Constructor

        /// <summary>
        /// Default constructor.
        /// </summary>
        public Index() { }

        #endregion
        #region Private Instance Fields

        private IndexItemCollection _items = new IndexItemCollection();
        private ImageReferenceCollection _imageReferences = new ImageReferenceCollection();
        private string _fileName;
        private string _manuscriptName;

        #endregion
        #region Public Properties

        public IndexItemCollection Items
        {
            get { return _items; }
            set { _items = value; }
        }

        public ImageReferenceCollection ImageReferences
        {
            get { return _imageReferences; }
            set { _imageReferences = value; }
        }

        public string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }

        public string ManuscriptName
        {
            get { return _manuscriptName; }
            set { _manuscriptName = value; }
        }

        #endregion

        /// <summary>
        /// Gets the index from the directory, if the index exists.
        /// </summary>
        /// <param name="directoryPath">The directory within which there is theoretically an index file.</param>
        /// <returns>Object of type Index.</returns>
        public static Index GetIndex(string directoryPath)
        {
            return IndexProvider.Instance.GetIndex(directoryPath);
        }

        /// <summary>
        /// Exports the images references from the index to a text file.
        /// </summary>
        /// <param name="filePath">The path that the exported file is to be saved to.</param>
        public void Export(string filePath)
        {
            IndexProvider.Instance.ExportToTextFile(this, filePath);
        }

        /// <summary>
        /// Saves the index back to disk.
        /// </summary>
        public void Save()
        {
            IndexProvider.Instance.Save(this);
        }

        public static Index CreateNewIndex(string directoryPath, string indexName)
        {
            return IndexProvider.Instance.CreateIndex(directoryPath, indexName);
        }
    }
}
